package com.uinnova.product.eam.workable.listener;

import com.uinnova.product.eam.workable.util.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.HistoryService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Slf4j
@Component("measureStatisticListener")
public class MeasureStatisticListener implements ExecutionListener {

    @Value("${measure.statistic.url: }")
    private String measureStatisticUrl;

    @Autowired
    private transient HistoryService historyService;

    @Autowired
    private HttpUtil httpUtil;

    @Override
    public void notify(DelegateExecution execution) {
        //获取当前流程实例业务主键
        String processInstanceBusinessKey = execution.getProcessInstanceBusinessKey();
        log.info("当前流程业务主键：{}", processInstanceBusinessKey);
        String requestUrl = measureStatisticUrl+"?processInstanceId="+execution.getProcessInstanceId()+"&businessKey="+processInstanceBusinessKey;
        log.info("度量统计:{}",requestUrl);
        httpUtil.get(requestUrl);
    }
}
